#!/usr/bin/perl
use strict;

###############################################################################
# This file will count the number of lenders in each file.
# (thanks to Jason The Mad Beaker for the code)
# Usage: Change "$i <= X" to the number of lender XML files, run the program
#   in the same directory as the files.
###############################################################################
my $globalCount = 0;

for(my $i = 1; $i <= 480; $i++)
{
  my $fileName = "$i.xml";
  my $fileCount=0;
  open (FILEHANDLE, "$fileName") || die "wrong filename";
  
  while ($fileName = <FILEHANDLE>)
  {
    while ($fileName =~ /<lender>/ig) #Count number of lenders
    #while ($fileName =~ /<lender><name>/ig) #Look for lenders missing a lender_id
    {
      ++$fileCount;
    }
  }
  
  $globalCount = $globalCount + $fileCount;
  print "$i.xml: $fileCount\n";
  close (FILEHANDLE);
}
print "\n\n\nTotal Number of Lenders: $globalCount\n";
